package com.weidian.mobile.open.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import com.tls.sigcheck.tls_sigcheck;

public class SignUtils {
	private String sign;

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}
	
	public SignUtils(String libPath, String keyPath) throws Exception{
		tls_sigcheck demo = new tls_sigcheck();

        demo.loadJniLib("D:\\work\\weidian_mobile_open\\weidian_mobile_open\\src\\main\\resources\\jnisigcheck_mt_x64.dll");
//        demo.loadJniLib("D:\\work\\weidian_mobile_open\\weidian_mobile_open\\src\\main\\resources\\jnisigcheck_mt_x64.so");

        File priKeyFile = new File("D:\\work\\weidian_mobile_open\\weidian_mobile_open\\src\\main\\resources\\private_key");
        StringBuilder strBuilder = new StringBuilder();
        String s = "";

        BufferedReader br = new BufferedReader(new FileReader(priKeyFile));
        while ((s = br.readLine()) != null) {
            strBuilder.append(s + '\n');
        }
        br.close();
        String priKey = strBuilder.toString();        
                int ret = demo.tls_gen_signature_ex2("1400104575", "malone", priKey);

        if (0 != ret) {
            System.out.println("ret " + ret + " " + demo.getErrMsg());
        }
        else
        {
            setSign(demo.getSig());
        }
	}

}
